package com.qf.controller;

import com.qf.pojo.User;
import org.springframework.web.bind.annotation.*;

/**
 * @CrossOrigin：指定允许跨域访问的地址
 */
@RestController
@RequestMapping("/test")
//@CrossOrigin("http://localhost:8081")
public class TestController {

//    @PathVariable 把rest url路径中的数据映射到参数中
    @GetMapping("/{id}")
    public User findById(@PathVariable("id") Integer aid){
        System.out.println("get:"+aid);
        User user = new User();
        user.setName("sss");
        user.setId(1);
        user.setAge(18);
        user.setSex('男');
        return user;
    }

    @PostMapping("")
    public String add(@RequestBody User user){
        System.out.println(user);
        return "success";
    }

    @PutMapping("")
    public String update(@RequestBody User user){
        System.out.println(user);
        return "success";
    }


    @DeleteMapping("/{id}")
    public String delete(@PathVariable Integer id){
        System.out.println(id);
        return "success";
    }
}
